package com.xzx.shop_front_api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xzx.shop_front_api.entity.Comment;
import com.xzx.shop_front_api.mapper.CommentMapper;
import com.xzx.shop_front_api.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;
    @Override
    public List<Comment> getCommentByGoodsId(int goodsId,int page,int limit) {
        int offset = (page - 1) * limit;
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("goods_id", goodsId);
        queryWrapper.eq("status", 1);
        queryWrapper.orderByDesc("created_time");
        queryWrapper.last("limit "+offset+","+limit);
        return commentMapper.selectList(queryWrapper);
    }
}
